Skip to content

Add unique id base methods - #62

Merged
ritch merged 6 commits into
3.0from
refactor/identifiers
Jul 3, 2014
Merged

Add unique id base methods#62
ritch merged 6 commits into
3.0from
refactor/identifiers

Conversation

@ritch

@ritch ritch commented Jun 30, 2014

Copy link
Copy Markdown
Member

/to @bajtos

This refactors all identifiers for workspace entities. It uses the idName(model) and provides the right value based on the configuration of the entity (in models.json). By default it will set

idName = componentName + name

In models.json we can set an additional id part to create a more specific id when required.

componentName + modelName + name

Comment thread models.json Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move the id property to Definition model? Is there any Definition subclass that does not have the id property?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ComponentDefinition should be keyed by name.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

@bajtos

bajtos commented Jul 1, 2014

Copy link
Copy Markdown
Member

The issue I am running into is that IDs are not so easily hookable. Could you look into hooking IDs? I tried a beforeSave hook, but that doesn't provide any reference to the constructor.

I don't understand, what do you mean by hooking ids? What are you trying to accomplish?

@bajtos

bajtos commented Jul 1, 2014

Copy link
Copy Markdown
Member

Once this is landed, we need to fix the way how ModelAccessControl ids are used and modify the serialization to remove them from the JSON output (see #53)

@ritch

ritch commented Jul 1, 2014

Copy link
Copy Markdown
Member Author

I don't understand, what do you mean by hooking ids? What are you trying to accomplish?

There isn't a hook in loopback to allow us to set the ID using a prototype method. We have beforeSave but it only provides the data and not the instanceof the constructor. So we can't provide a single hook function that calls getUniqueId().

@bajtos

bajtos commented Jul 1, 2014

Copy link
Copy Markdown
Member

There isn't a hook in loopback to allow us to set the ID using a prototype method. We have beforeSave but it only provides the data and not the instanceof the constructor. So we can't provide a single hook function that calls getUniqueId().

Keep in mind that yo loopback calls the API directly, thus no hooks are invoked. Let's discuss this online in a chat.

@bajtos bajtos added this to the 3.0 milestone Jul 1, 2014
@ritch

ritch commented Jul 1, 2014

Copy link
Copy Markdown
Member Author

@bajtos can we land this first? If it looks good to you and I am not around please merge.

Comment thread models/definition.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have dropped the debug statement, is it intentional? The same question applies to the Array.isArray branch above.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added them back without id

@ritch ritch changed the title [WIP] Add unique id base methods Add unique id base methods Jul 2, 2014
Comment thread models.json Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last item has a trailing comma - the JSON is malformed.

@bajtos

bajtos commented Jul 3, 2014

Copy link
Copy Markdown
Member

@ritch The patch does not merge cleanly with the current 3.0, could you please rebase and resolve conflicts? When I attempted to make the rebase myself, I arrived at code that was not passing all tests.

Comment thread models/definition.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reduntant, as entity is not used anywhere AFAICT.

I would be also worried about creating Models at the point when the connector cache is in a possibly inconsistent state.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

@bajtos

bajtos commented Jul 3, 2014

Copy link
Copy Markdown
Member

Two more comments. Other than that, the patch LGTM. Feel free to merge.

ritch added 4 commits July 3, 2014 11:22
 - allow `WorkspaceEntity` to determine the unique id
 - `connector.create` should callback with an id
 - all models should not have the correct `id` property
 - pass the correct identifier data to `addRelatedCache` so it can set
the `componentName` and the correct foreign key
 - clean related data for both embedded arrays and objects
 - remove `componentName` and `id` for all embedded config data
 - ensure the value being set to the cache has the correct id
 - add id tests (could use more for other model types)
 - rename model foreign key
 - remove modelName property from all entities
 - remove componentName from entities where it was made redundant by
the parent id (eg. modelProperty.modelId has the componentName)
 - allow for simpler id building by adding belongsTo relationships
 - use belongs to relations to build the id
 - parentIds (belongsTo foreignKeys) are now required
 - cleanup data (eg. dataSourceDef.id) leaking into config files
@ritch

ritch commented Jul 3, 2014

Copy link
Copy Markdown
Member Author

@bajtos rebased and all tests are passing. Had to fix a couple minor things.

ritch added a commit that referenced this pull request Jul 3, 2014
@ritch
ritch merged commit 2c3e3fb into 3.0 Jul 3, 2014
@bajtos bajtos mentioned this pull request Jul 4, 2014
12 tasks
@rmg
rmg deleted the refactor/identifiers branch June 21, 2016 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants